package com.gooluke.shorten.util;

public class Base62 {

    public static final char[] CHAR_SET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();

    public String encode(long number) {
        if (number == 0) return "0";
        StringBuilder sb = new StringBuilder();
        while (number > 0) {
            int remainder = (int) (number % 62);
            sb.append(CHAR_SET[remainder]);
            number = number / 62;
        }
        return sb.reverse().toString();
    }
}